/*
 *    Copyright (c) 2014 Xiang Xu <xuxiang@mail.bnu.edu.cn>
 *
 *    Permission is hereby granted, free of charge, to any person
 *    obtaining a copy of this software and associated documentation
 *    files (the "Software"), to deal in the Software without
 *    restriction, including without limitation the rights to use,
 *    copy, modify, merge, publish, distribute, sublicense, and/or sell
 *    copies of the Software, and to permit persons to whom the
 *    Software is furnished to do so, subject to the following
 *    conditions:
 *
 *    The above copyright notice and this permission notice shall be
 *    included in all copies or substantial portions of the Software.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 *    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 *    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 *    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 *    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 *    OTHER DEALINGS IN THE SOFTWARE.
 */


#ifndef SPLITACTION_H
#define SPLITACTION_H

#include <string>

//! Split action
/*! This class is used by RL Learning. It is the brief describe of Rule structure.*/
class SplitAction
{
public:
    SplitAction() {}

    //! Constructor
    /*!
     *	\param name Action name.
     *	\param parameter Split length.
     *	\param grammar_index The grammar rule that this Action belongs to.
     */
    SplitAction(std::string name, double parameter, int grammar_index = -1)
    {
        grammar_name_ = name, parameter_ = parameter;
        grammar_index_ = grammar_index;
    }

    //! Copy constructor
    SplitAction(const SplitAction& sa)
    {
        this->grammar_name_ = sa.grammar_name_;
        this->parameter_ = sa.parameter_;
        this->grammar_index_ = sa.grammar_index_;
    }

    //! Set the grammar rule index that this action belongs to.
    inline void set_shape_grammar(int grammar_index)
    {
        grammar_index_ = grammar_index;
    }
    //! Get the grammar rule index that this action belongs to.
    inline int get_shape_grammar_index()
    {
        return grammar_index_;
    }
    //! Get the rule name of this action.
    inline std::string get_grammar_name()
    {
        return grammar_name_;
    }
    //! Get the rule parameter of this action.
    inline double get_parameter()
    {
        return parameter_;
    }

    SplitAction& operator= (const SplitAction& action)
    {
        this->grammar_name_ = action.grammar_name_;
        this->parameter_ = action.parameter_;
        this->grammar_index_ = action.grammar_index_;

        return *this;
    }

    bool operator== (const SplitAction& sa) const
    {
        return (grammar_name_ == sa.grammar_name_ && parameter_ == sa.parameter_);
    }
    bool operator!= (const SplitAction& sa) const
    {
        return (grammar_name_ != sa.grammar_name_ || parameter_ != sa.parameter_);
    }

    bool operator> (const SplitAction& sa) const
    {
        if(parameter_ == sa.parameter_)
            return (grammar_name_ > sa.grammar_name_);
        else
            return (parameter_ > sa.parameter_);
    }

    bool operator< (const SplitAction& sa) const
    {
        if(parameter_ == sa.parameter_)
            return (grammar_name_ < sa.grammar_name_);
        else
            return (parameter_ < sa.parameter_);
    }

private:
    std::string grammar_name_; /*!< grammar rule name of this action. */
    double parameter_;		   /*!< grammar rule parameter of this action. */
    int grammar_index_;		   /*!< grammar rule index of this action. */
};

typedef SplitAction Facadestate;

#endif // SPLITACTION_H
